<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>shape.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_graphics_ext_shape.js.html">shape.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>
<a name="line16"></a>/**
<a name="line17"></a> * @fileoverview A thick wrapper around shapes with custom paths.
<a name="line18"></a> * @author robbyw@google.com (Robby Walker)
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.graphics.ext.Shape&#39;);
<a name="line23"></a>
<a name="line24"></a>goog.require(&#39;goog.graphics.ext.Path&#39;);
<a name="line25"></a>goog.require(&#39;goog.graphics.ext.StrokeAndFillElement&#39;);
<a name="line26"></a>goog.require(&#39;goog.math.Rect&#39;);
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * Wrapper for a graphics shape element.
<a name="line32"></a> * @param {goog.graphics.ext.Group} group Parent for this element.
<a name="line33"></a> * @param {!goog.graphics.ext.Path} path  The path to draw.
<a name="line34"></a> * @param {boolean=} opt_autoSize Optional flag to specify the path should
<a name="line35"></a> *     automatically resize to fit the element.  Defaults to false.
<a name="line36"></a> * @constructor
<a name="line37"></a> * @extends {goog.graphics.ext.StrokeAndFillElement}
<a name="line38"></a> * @final
<a name="line39"></a> */
<a name="line40"></a>goog.graphics.ext.Shape = function(group, path, opt_autoSize) {
<a name="line41"></a>  this.autoSize_ = !!opt_autoSize;
<a name="line42"></a>
<a name="line43"></a>  var graphics = group.getGraphicsImplementation();
<a name="line44"></a>  var wrapper = graphics.drawPath(path, null, null,
<a name="line45"></a>      group.getWrapper());
<a name="line46"></a>  goog.graphics.ext.StrokeAndFillElement.call(this, group, wrapper);
<a name="line47"></a>  this.setPath(path);
<a name="line48"></a>};
<a name="line49"></a>goog.inherits(goog.graphics.ext.Shape, goog.graphics.ext.StrokeAndFillElement);
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>/**
<a name="line53"></a> * Whether or not to automatically resize the shape&#39;s path when the element
<a name="line54"></a> * itself is resized.
<a name="line55"></a> * @type {boolean}
<a name="line56"></a> * @private
<a name="line57"></a> */
<a name="line58"></a>goog.graphics.ext.Shape.prototype.autoSize_ = false;
<a name="line59"></a>
<a name="line60"></a>
<a name="line61"></a>/**
<a name="line62"></a> * The original path, specified by the caller.
<a name="line63"></a> * @type {goog.graphics.Path}
<a name="line64"></a> * @private
<a name="line65"></a> */
<a name="line66"></a>goog.graphics.ext.Shape.prototype.path_;
<a name="line67"></a>
<a name="line68"></a>
<a name="line69"></a>/**
<a name="line70"></a> * The bounding box of the original path.
<a name="line71"></a> * @type {goog.math.Rect?}
<a name="line72"></a> * @private
<a name="line73"></a> */
<a name="line74"></a>goog.graphics.ext.Shape.prototype.boundingBox_ = null;
<a name="line75"></a>
<a name="line76"></a>
<a name="line77"></a>/**
<a name="line78"></a> * The scaled path.
<a name="line79"></a> * @type {goog.graphics.Path}
<a name="line80"></a> * @private
<a name="line81"></a> */
<a name="line82"></a>goog.graphics.ext.Shape.prototype.scaledPath_;
<a name="line83"></a>
<a name="line84"></a>
<a name="line85"></a>/**
<a name="line86"></a> * Get the path drawn by this shape.
<a name="line87"></a> * @return {goog.graphics.Path?} The path drawn by this shape.
<a name="line88"></a> */
<a name="line89"></a>goog.graphics.ext.Shape.prototype.getPath = function() {
<a name="line90"></a>  return this.path_;
<a name="line91"></a>};
<a name="line92"></a>
<a name="line93"></a>
<a name="line94"></a>/**
<a name="line95"></a> * Set the path to draw.
<a name="line96"></a> * @param {goog.graphics.ext.Path} path The path to draw.
<a name="line97"></a> */
<a name="line98"></a>goog.graphics.ext.Shape.prototype.setPath = function(path) {
<a name="line99"></a>  this.path_ = path;
<a name="line100"></a>
<a name="line101"></a>  if (this.autoSize_) {
<a name="line102"></a>    this.boundingBox_ = path.getBoundingBox();
<a name="line103"></a>  }
<a name="line104"></a>
<a name="line105"></a>  this.scaleAndSetPath_();
<a name="line106"></a>};
<a name="line107"></a>
<a name="line108"></a>
<a name="line109"></a>/**
<a name="line110"></a> * Scale the internal path to fit.
<a name="line111"></a> * @private
<a name="line112"></a> */
<a name="line113"></a>goog.graphics.ext.Shape.prototype.scaleAndSetPath_ = function() {
<a name="line114"></a>  this.scaledPath_ = this.boundingBox_ ? this.path_.clone().modifyBounds(
<a name="line115"></a>      -this.boundingBox_.left, -this.boundingBox_.top,
<a name="line116"></a>      this.getWidth() / (this.boundingBox_.width || 1),
<a name="line117"></a>      this.getHeight() / (this.boundingBox_.height || 1)) : this.path_;
<a name="line118"></a>
<a name="line119"></a>  var wrapper = this.getWrapper();
<a name="line120"></a>  if (wrapper) {
<a name="line121"></a>    wrapper.setPath(this.scaledPath_);
<a name="line122"></a>  }
<a name="line123"></a>};
<a name="line124"></a>
<a name="line125"></a>
<a name="line126"></a>/**
<a name="line127"></a> * Redraw the ellipse.  Called when the coordinate system is changed.
<a name="line128"></a> * @protected
<a name="line129"></a> * @override
<a name="line130"></a> */
<a name="line131"></a>goog.graphics.ext.Shape.prototype.redraw = function() {
<a name="line132"></a>  goog.graphics.ext.Shape.superClass_.redraw.call(this);
<a name="line133"></a>  if (this.autoSize_) {
<a name="line134"></a>    this.scaleAndSetPath_();
<a name="line135"></a>  }
<a name="line136"></a>};
<a name="line137"></a>
<a name="line138"></a>
<a name="line139"></a>/**
<a name="line140"></a> * @return {boolean} Whether the shape is parent dependent.
<a name="line141"></a> * @protected
<a name="line142"></a> * @override
<a name="line143"></a> */
<a name="line144"></a>goog.graphics.ext.Shape.prototype.checkParentDependent = function() {
<a name="line145"></a>  return this.autoSize_ ||
<a name="line146"></a>      goog.graphics.ext.Shape.superClass_.checkParentDependent.call(this);
<a name="line147"></a>};
</pre>


</body>
</html>
